package com.gsm.projects.jobDw.mock;

import com.github.javafaker.Faker;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Locale;

public class EmployerDataGenerator {

    public static void main(String[] args) {
        // 数据库配置
        String url = "jdbc:mysql://localhost:3306/db_job_realtime_statistics?useSSL=false&serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8";
        String user = "root";
        String password = "123456";

        // 生成数据的数量
        int numberOfRecords = 1000; // 你可以根据需要调整这个数量

        try (Connection conn = DriverManager.getConnection(url, user, password)) {

            Faker faker = new Faker(new Locale("zh_CN"));

            String sql = "INSERT INTO Employers (name, address, industry, contact_info) VALUES (?, ?, ?, ?)";
            PreparedStatement stmt = conn.prepareStatement(sql);

            for (int i = 0; i < numberOfRecords; i++) {

                stmt.setString(1, faker.company().name()); // name
                stmt.setString(2, faker.address().city()); // address
                stmt.setString(3, faker.company().industry()); // industry
                stmt.setString(4, faker.internet().emailAddress()); // contact_info

                stmt.addBatch();
                if (i % 100 == 0 || i == numberOfRecords - 1) { // 批量执行以提高效率
                    stmt.executeBatch();
                }
            }

            System.out.println("Data generation and insertion completed successfully.");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}